package com.chengjj.kings.core.base.controller;

import com.chengjj.kings.core.reqres.response.SuccessResponseData;
import com.chengjj.kings.core.util.HttpContext;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Objects;

/**
 * @Author: 成俊杰
 * @CreateDate: 2019/3/7
 * @Version: 1.0
 * @Description: Controller基础包
 */
public class BaseController {
    protected final String REDIRECT = "redirect:";
    protected final String FORWARD = "forward";
    protected static SuccessResponseData SUCCESS_TIP = new SuccessResponseData();

    public BaseController() {
    }

    protected HttpServletRequest getHttpServletRequest() {
        return HttpContext.getRequest();
    }

    protected HttpServletResponse getHttpServletResponse() {
        return HttpContext.getResponse();
    }

    protected HttpSession getSession() {
        return ((HttpServletRequest) Objects.requireNonNull(HttpContext.getRequest())).getSession();
    }

    protected HttpSession getSession(Boolean flag) {
        return ((HttpServletRequest) Objects.requireNonNull(HttpContext.getRequest())).getSession(flag);
    }

    protected String getPara(String name) {
        return ((HttpServletRequest) Objects.requireNonNull(HttpContext.getRequest())).getParameter(name);
    }

    protected void setAttr(String name, Object value) {
        ((HttpServletRequest) Objects.requireNonNull(HttpContext.getRequest())).setAttribute(name, value);
    }

}
